package com.ljkj.cordial.chat.util;

import com.lanjiu.lib.imclient.user.UserPreferences;
import com.lanjiu.lib.utils.sp.SPKeys;
import com.lanjiu.lib.utils.sp.SharedPreferenceHelper;

/**
 * @description:
 * @author: Panwei
 * @date: 2020/3/11 14:23
 */
public class InitializeKit {

    private static final long GROUP_INIT_PERIOD = 24 * 60 * 60 * 1000;

    private InitializeKit() {
    }

    public static void friendInitialized() {
        SharedPreferenceHelper.create(SPKeys.Name.CONFIG).setBoolean(SPKeys.Key.CONFIG_INIT_FRIEND + UserPreferences.getUserId(), false);
    }

    public static boolean isFriendInitialize() {
        return SharedPreferenceHelper.create(SPKeys.Name.CONFIG).getBoolean(SPKeys.Key.CONFIG_INIT_FRIEND + UserPreferences.getUserId(), true);
    }

    public static void groupInitialized() {
        SharedPreferenceHelper.create(SPKeys.Name.CONFIG).setLong(SPKeys.Key.CONFIG_INIT_GROUP + UserPreferences.getUserId(), System.currentTimeMillis());
    }

    public static boolean isGroupInitialize() {
        long groupLastInitialize = SharedPreferenceHelper.create(SPKeys.Name.CONFIG).getLong(SPKeys.Key.CONFIG_INIT_GROUP + UserPreferences.getUserId());
        if (groupLastInitialize <= 0)
            return true;
        return System.currentTimeMillis() - groupLastInitialize >= GROUP_INIT_PERIOD;
    }

    public static void clear() {
        SharedPreferenceHelper.create(SPKeys.Name.CONFIG).delete(SPKeys.Key.CONFIG_INIT_FRIEND + UserPreferences.getUserId());
        SharedPreferenceHelper.create(SPKeys.Name.CONFIG).delete(SPKeys.Key.CONFIG_INIT_GROUP + UserPreferences.getUserId());
    }
}
